package leetcode.solution203;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 * int val;
 * ListNode next;
 * ListNode(int x) { val = x; }
 * }
 */
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public ListNode(int []nums){
        if(nums == null && nums.length<=0){
            throw new IllegalArgumentException("illegal nums");
        }
        ListNode cur = this;
        this.val = nums[0];
        for(int i=1;i<nums.length;i++){
            cur.next = new ListNode(nums[i]);
            cur = cur.next;

        }


    }

    @Override
    public String toString(){
        StringBuilder stringBuilder = new StringBuilder();
        ListNode cur = this;
        while (cur != null){
            stringBuilder.append(cur.val+"->");
            cur = cur.next;
        }

        stringBuilder.append("NULL");
        return stringBuilder.toString();
    }


}
